document.write('<script type="text/javascript" src="../js/error/js/userStateUnusual.js"></script>');
document.write('<script type="text/javascript" src="../js/json2.js"></script>');

/**
 * 处理服务器返回的JSON数据，并显示成功的DIY消息或失败的DIY消息
 * @param jsonData 服务器返回的JSON数据
 * @param msgSuss DIY的成功消息
 * @param msgError DIY的失败消息
 * @returns
 */
function DealAndShowDiyMsg(jsonData,msgSuss,msgError){
	var json = checkStateShowErrorMsgAndDealResult(jsonData);
	if(!isNull(json)){
		if (json.state==0) {
			//when json state code is zero
			showSuccessMsgWin(msgSuss);
		}else if(json.state==1){
			//when json state code is one
			showErrMsgWin(msgError);
		}
	}
	return json;
}

/**
 * 处理服务器返回的JSON数据，并决定是否显示成功或失败的消息
 * @param jsonData 服务器返回的JSON数据
 * @param isShowSussMsg 是否提示操作成功消息
 * @param isShowErrMsg 是否提示操作失败消息
 * @returns
 */
function DealAndShowMsg(jsonData,isShowSussMsg,isShowErrMsg){
	var json = checkStateShowErrorMsgAndDealResult(jsonData);
	if(!isNull(json)){
		var msg = "没有消息";
		if(!isNull(msg)){
			msg = json.msg;
		}
		if (json.state==0) {
			//when json state code is zero
			if(isShowSussMsg){
				showSuccessMsgWin(msg);
			}
		}else{
			//when json state code is one
			if(isShowErrMsg){
				showErrMsgWin(msg);
			}
		}
	}
	return json;
}

/**
 * 检查服务器返回的JSON数据。判断状态码，给出相应的提示信息
 * @param JsonData 服务器返回的JSON数据
 */
function checkStateShowErrorMsgAndDealResult(jsonData){
	var json = JSON.parse(jsonData);
	
	if(isNull(json)){
		showErrMsgWin("服务器响应状态异常");
	}else{
		var state = -1;
		if (json.state == null) {
			return null;
		} else {
			state = json.state;
		}
		if (state==0) {
			//when the return code is zero
		}else if(state==-1){
			//show window tip user not login code
			loginLoseError();
		}else if(state==2){
			//show window tip user is already double login code
			doubleLoginError();
		}else if(state==3){
			//show window tip user is not have enough power code
			noPowerError();
		}else if(state==1){
			//when the return code is one
		}else{
			showErrMsgWin("服务器响应状态异常");
		}
	}
	return json;
}


/**
 * 判空
 * @param obj 
 * @returns {Boolean}
 */
function isNull(obj){
	if(obj==null || obj=="" || obj==undefined)
		return true;
	else
		return false;
}

function isSuccess(json) {
	if (json.state==0) {
		return true;
	}
}

function isResult(json) {
	if (json.result != null) {
		return true;
	} else {
		return false;
	}
}

function isResultLen(json) {
	if (json.result != null) {
		if (json.result.len>=0) {
			return true;
		} else {
			return false;
		}
	} else {
		return false;
	}
}

function getResult(json) {
	if (json.result != null) {
		return json.result;
	} else {
		return null;
	}
}

function getResultHead(json) {
	if (json.result != null) {
		return json.result;
	} else {
		return null;
	}
}

function getResultData(json) {
	if (json.result != null) {
		return json.result;
	} else {
		return null;
	}
}

/*
function checkStateAndShowDiyMsg(JsonData,needShowSuccessMsg,needShowErrorMsg){
	var json = JSON.parse(JsonData);
	var state = json.state;
	if(state==-1){
		//show window tip user not login code
		loginLoseError();
	}else if(state==2){
		//show window tip user is already double login code
		doubleLoginError();
	}else if(state==1){
		//show error tip code
		showErrMsgWin(needShowErrorMsg);
	}else if(state!=0){
		showErrMsgWin("服务器响应状态异常");
	}else{
		//when the return code is zero
		showSuccessMsgWin(needShowSuccessMsg);
	}
}
*/